﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Admx_Generator
{
    public class Category : IEquatable<Category>
    {
        /// <summary>
        /// Create a new instance of a Category.
        /// </summary>
        /// <param name="name">Name of the category.</param>
        /// <param name="displayName">Id used to retrieve the display name in the Adml files. String.Emtpy if not define.</param>
        /// <param name="explainText">Id used to retrieve the explain text in the Adml files. String.Empty if not define.</param>
        /// <param name="parentCategoryReference">A link to the parent category. Null if there is no parent category.</param>
        public Category(string name, string displayName, string explainText, Reference parentCategoryReference)
        {
            this.Name = name;
            this.ParentCategory = parentCategoryReference;
            this.DisplayName = String.IsNullOrEmpty(displayName) ? "$(string." + name + ")" : displayName;
            this.ExplainText = String.IsNullOrEmpty(explainText) ? String.Empty : explainText; ;
        }

        #region (properties)

        /// <summary>
        /// Gets or Sets the name of this Category.
        /// </summary>
        public string Name { get; private set; }

        /// <summary>
        /// Gets or Sets the id used to retrieve the display name in the Adml files.
        /// </summary>
        public string DisplayName { get; private set; }

        /// <summary>
        /// Gets or Sets the id used to retrieve the explain text in the Adml file.
        /// </summary>
        public string ExplainText { get; private set; }

        public Reference ParentCategory { get; private set; }

        #endregion (properties)

        public bool Equals(Category other)
        {
            if (other == null)
                return false;
            return (String.Compare(this.Name, other.Name, StringComparison.InvariantCultureIgnoreCase) == 0 &&
                ((this.ParentCategory == null && other.ParentCategory == null) || (this.ParentCategory != null && other.ParentCategory != null && this.ParentCategory.Equals(other.ParentCategory))));
        }

        public override bool Equals(object obj)
        {
            return Equals(obj as Category);
        }

        public override int GetHashCode()
        {
            return base.GetHashCode();
        }
    }
}
